import json
import redis

conn = redis.Redis()

try:
    visitor_total = conn.get('visitor_total').decode('utf-8')
except Exception as e:
    visitor_total = 0
    print(e)
    print('fail to get visitor_total')

card_list = conn.keys('cardNum_*')
img_list = conn.keys('citem_*')

print('总共访问人次：', visitor_total, '人次')

for key in card_list:
    print(key.decode('utf-8'), ': ', conn.get(key).decode('utf-8'), '人次')

i = 1
for key in img_list:
    data = json.loads(conn.get(key).decode('utf-8'))
    print('img_{}'.format(i), ': ')
    print('    ', '收件人：', data['receiver'])
    print('    ', '发件人：', data['writer'])
    print('    ', '贺卡号：', data['cardNum'])
    print('    ', '内  容：', data['content'])
    i += 1
